package cn.kailangtu.dataspot.tasks;

import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import cn.kailangtu.commontools.CommonUtils;
import cn.kailangtu.dataspot.status;
import cn.kailangtu.serialutils.modbus.modbusUtil;

public abstract class BaseTask {
    protected boolean isRun = true;
    protected int isWaitReadIndexCom;
    protected int indexCom;
    protected int taskStatus;
    protected  List<byte[]> lsReadCom = new ArrayList<>();
    protected List<byte[]> lsReadCom485 = new ArrayList<>();
    protected boolean isWaitReadCom = false;
    protected static LinkedBlockingQueue<byte[]>  plcQuere = new LinkedBlockingQueue<>();
    protected static LinkedBlockingQueue<byte[]> temperatureQuere = new LinkedBlockingQueue<>();
    protected static  LinkedBlockingQueue<byte[]> queueDianNeng = new LinkedBlockingQueue<>();
    abstract void init();
    abstract void close();
    protected long sendTime=0;
    protected long receiveTime=0;

    public int getTaskStatus() {
        return taskStatus;
    }

    public void setTaskStatus(int taskStatus) {
        this.taskStatus = taskStatus;
    }

    public static void addNewPLCCommand(byte[] newData)
    {
        plcQuere.offer(newData);
    }

    public static void addNewDianNenCommand(byte[] newData){
        queueDianNeng.offer(newData);
    }

    public static void addNewTemperatureTask(byte[] newData){
        temperatureQuere.offer(newData);
    }

    public static void toNewPage(int pageIndex)
    {
        Log.d("TAGECHANGE","pageIndex:"+pageIndex);
        status.localToPlc = 1;
        byte[] cmd = modbusUtil.writeToOne(1, CommonUtils.int2ByteArray(3529), new byte[]{0x00, (byte)pageIndex});
        plcQuere.offer(cmd);

    }
}
